<template>
	<view class="yonghufankui">
		<view class="box-content">
			<textarea v-model="content" placeholder="输入需要反馈的问题" placeholder-color="#999999"></textarea>
		</view>
		<!-- 上传图片 -->
		<view class="releaseGoodsItemUpload">
		  <view v-for="(item,index) in photoList" :key="index" class="photoListItem">
			<image class="photoListItemImg" :src="item" @click="ViewImage(photoList[index])"></image>
			<view class="delImage" @click="DelImg(index)">
			    <image src="http://juebai.oss-cn-hangzhou.aliyuncs.com/webStorage/web_16147431265761867.png"></image>
			</view>
		  </view>
		  <image class="upload" @click="handleUpload" v-if="photoList.length < 9" src="../../static/sc_tp@2x.png" mode=""></image>
		</view>
		<view class="box-btn">
			<view class="btn" @click="handletijiao">
				提交反馈
			</view>
		</view>
	</view>
</template>

<script>
	var uploadImage = require('../../common/uploadFile.js');//地址换成你自己存放文件的位置
	var util = require('../../common/formatTime.js');
	export default {
		data() {
			return {
				content:'',
				photoList:[],
				share:uni.getStorageSync('share')
			}
		},
		methods: {
			//上传图片
			  handleUpload(){
			    var that = this;
			    uni.chooseImage({
			      count: 9, // 默认最多一次选择9张图
			      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
			      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
			      //sourceType: ['album'],
			      success: function (res) {
			        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
			        var tempFilePaths = res.tempFilePaths;
					console.log(res.tempFilePaths)
			        var nowTime = util.formatTime(new Date());
			        //支持多图上传
			        console.log(res.tempFilePaths,12)
			        for (var i = 0; i < res.tempFilePaths.length; i++) {
			          //显示消息提示框
			          uni.showLoading({
			            title: '上传中' + (i + 1) + '/' + res.tempFilePaths.length,
			            mask: true
			          })
			          //上传图片
			          //你的域名下的/cbb文件下的/当前年月日文件下的/图片.png
			          //图片路径可自行修改
			          // uploadImage(res.tempFilePaths[i], 'bad/' + nowTime + '/',
			          uploadImage(res.tempFilePaths[i], 'loveFruit/',
			            function (result) {
			              console.log("======上传成功图片地址为：", result);
			              //做你具体的业务逻辑操作
						  that.photoList = that.photoList.concat(result.split(','))
			              uni.hideLoading();
			           }, function (result) {
			            console.log("======上传失败======", result);
			            //做你具体的业务逻辑操作
			                   uni.hideLoading()
			                }
			             )
			          }
			       }
			    })
			},
			ViewImage(url) {
			    uni.previewImage({
			      urls: this.photoList,
			      current: url
			    });
			},
			DelImg(index) {
			    this.photoList.splice(index, 1);
			    
			},
			//提交反馈
			async handletijiao(){
				const params = {
					content:this.content,
					picUrls:this.photoList
				}
				const res = await this.$u.api.submitFeedback(params)
				this.$u.toast(res.msg)
				if (res.code == 0) {
					this.content = ''
					this.photoList = []
				}
			}
		}
	}
</script>
<style>
	page{
		background: #FBFBFB;
	}
</style>
<style scoped lang="scss">
	.yonghufankui{
		padding-top: 28rpx;
	}
	.box-content{
		padding: 28rpx;
		background: white;
	}
	.box-content textarea{
		width: 100%;
		font-size: 28rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		line-height: 32rpx;
	}
	
	.releaseGoodsItemUpload{
	  display: flex;
	  flex-direction: row;
	  flex-wrap: wrap;
	  padding: 50rpx 28rpx;
	}
	.photoListItem{
	  width: 140rpx;
	  height: 140rpx;
	  position: relative;
	  margin: 0rpx 20rpx 20rpx 0rpx;
	}
	.photoListItemImg{
	  width: 140rpx;
	  height: 140rpx;
	  border-radius: 10px;
	}
	.delImage image{
	  width: 40rpx;
	  height: 40rpx;
	  position: absolute;
	  top: 0;
	  right: 0;
	}
	.upload{
	  margin-bottom: 24rpx;
	  width: 140rpx;
	  height: 140rpx;
	}
	
    .box-btn{
    	padding: 10rpx 28rpx 0rpx 28rpx;
    	width: 750rpx;
    	height: 168rpx;
    	background: #FFFFFF;
        border-top: 0.5px solid #E3E3E3;
    	position: fixed;
    	left: 0;
    	bottom: 0;
    }
    .btn{
    	width: 694rpx;
    	height: 84rpx;
    	background: url('http://hmh-app.oss-cn-beijing.aliyuncs.com/webStorage/web_16919793742137642.png') no-repeat;
    	background-size: 100% 100%;
    	font-size: 32rpx;
    	font-family: PingFang SC-Bold, PingFang SC;
    	font-weight: bold;
    	color: #FFFFFF;
    	line-height: 84rpx;
    	text-align: center;
    }
</style>
